package mn.slide.labmed.adapter;

import java.util.ArrayList;

import mn.slide.labmed.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MerklisteAdapter extends ArrayAdapter<String> {
	private final Activity context;
	private final ArrayList<String> names;

	public MerklisteAdapter(Activity context, ArrayList<String> names) {
		super(context, R.layout.row, names);
		this.context = context;
		this.names = names;
	}

	static class ViewHolderMerk {
		public TextView textView;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolderMerk holder;
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.row, null, true);
			holder = new ViewHolderMerk();
			notifyDataSetChanged();
			holder.textView = (TextView) rowView.findViewById(R.id.label);
			rowView.setTag(holder);
		} else {
			holder = (ViewHolderMerk) rowView.getTag();
		}
		rowView.setBackgroundResource(R.drawable.row_background);
		holder.textView.setText(names.get(position));
		return rowView;
	}

}